package cn.kgc.mvc.controller;

import cn.kgc.mvc.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: mosin
 * @version: v1.0  2022/7/7
 */
//@RestController
@Controller
@RequestMapping("json")
public class JSONController {


    @RequestMapping("j1")
    @ResponseBody // 返回值 转换成json格式
    public User test01(){
        System.out.println("ajax请求已接收");
        User user = new User();
        user.setUsername("tom");
        user.setPassword("123");
        user.setAge(20);
        return  user;
    }


    @RequestMapping("j2")
    @ResponseBody // 返回值 转换成json格式
    public User test02(@RequestBody User user){  //  参数接收时  前端传递的参数类型json格式  {"username" ="lisi" }
        System.out.println("user = " + user);
        return  user;
    }
}
